package com.tencent.sr.iris.basic.saas.service.model.activity;

import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.StrUtil;
import com.alibaba.excel.annotation.ExcelProperty;
import com.alibaba.excel.annotation.write.style.ColumnWidth;
import com.tencent.sr.iris.basic.saas.common.enums.TaskRecordAwardIssueStatusEnum;
import com.tencent.sr.iris.basic.saas.common.utils.CommonUtils;
import com.tencent.sr.iris.basic.saas.interfaces.response.activity.ActivityTaskPageResponse;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;

import java.util.Map;
import java.util.Objects;
import java.util.Optional;

@Data
@ApiModel(value = "活动明细导出信息")
@Slf4j
@ColumnWidth(15)
public class RegistGiftActivityTaskExportInfo extends BaseActivityTaskExportInfo {

    @ExcelProperty(value = "推送发奖时间", index = 17)
    private String awardSendTime;

    @ExcelProperty(value = "券金额", index = 18)
    private Double awardAmount;

    @ExcelProperty(value = "券领取时间", index = 19)
    private String awardRecordTime;

    @ExcelProperty(value = "券核销时间", index = 20)
    private String consumeTime;

    @Override
    public void readFromSearchResponseData(ActivityTaskPageResponse response, Map<Long, String> areaMap) {
        super.readFromSearchResponseData(response, areaMap);
        Double awardAmount = CommonUtils.integerToDouble(response.getAwardAmount());
        this.setAwardAmount(awardAmount);

        String awardRecordTime = Optional.ofNullable(response.getAwardRecordTime())
                .map(i -> DateUtil.formatDateTime(DateUtil.date(i))).orElse(StrUtil.EMPTY);
        this.setAwardRecordTime(awardRecordTime);

        String consumeTime = Optional.ofNullable(response.getConsumeTime())
                .map(i -> DateUtil.formatDateTime(DateUtil.date(i))).orElse(StrUtil.EMPTY);
        this.setConsumeTime(consumeTime);

        if (Objects.equals(response.getAwardIssueStatus(),
                String.valueOf(TaskRecordAwardIssueStatusEnum.ISSUE_SUCCEED.getCode()))) {
            //已发奖
            String awardSendTime = Optional.ofNullable(response.getAwardSendTime())
                    .map(i -> DateUtil.formatDateTime(DateUtil.date(i))).orElse(StrUtil.EMPTY);
            this.setAwardSendTime(awardSendTime);
        } else {
            this.setAwardSendTime(StrUtil.DASHED);
        }
    }
}
